package com.vn.ld.btc.dao.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.vn.ld.common.Constants.ServiceType;


/**
 * The persistent class for the customer_services database table.
 */
@Entity
@Table(name = "customer_services")
@NamedQuery(name = "CustomerService.findAll", query = "SELECT c FROM CustomerService c")
public class CustomerService implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "customer_service_id", unique = true, nullable = false)
	private Integer customerServiceId;

	@Column(name = "active_flg", nullable = false)
	private Integer activeFlg;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "input_date")
	private Date inputDate;

	@Column(name = "service_type")
	private Integer serviceTypeId;
	
	@Transient
	private ServiceType serviceType;
	
	@Column(nullable = false)
	private Integer status;

	@Column(name = "transaction_flg")
	private Integer transactionFlg;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_date")
	private Date updateDate;

	@Column(name = "withdraw_flg")
	private Integer withdrawFlg;

	// bi-directional many-to-one association to Customer
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "customer_id", nullable = false)
	private Customer customer;

	public CustomerService() {
	}

	public Integer getCustomerServiceId() {
		return this.customerServiceId;
	}

	public void setCustomerServiceId(Integer customerServiceId) {
		this.customerServiceId = customerServiceId;
	}

	public Integer getActiveFlg() {
		return this.activeFlg;
	}

	public void setActiveFlg(Integer activeFlg) {
		this.activeFlg = activeFlg;
	}

	public Date getInputDate() {
		return this.inputDate;
	}

	public void setInputDate(Date inputDate) {
		this.inputDate = inputDate;
	}

	public Integer getServiceTypeId() {
		return this.serviceTypeId;
	}

	public void setServiceTypeId(Integer serviceTypeId) {
		this.serviceTypeId = serviceTypeId;
	}

	public ServiceType getServiceType() {
		return serviceType;
	}

	public void setServiceType(ServiceType serviceType) {
		this.serviceType = serviceType;
	}

	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getTransactionFlg() {
		return this.transactionFlg;
	}

	public void setTransactionFlg(Integer transactionFlg) {
		this.transactionFlg = transactionFlg;
	}

	public Date getUpdateDate() {
		return this.updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public Integer getWithdrawFlg() {
		return this.withdrawFlg;
	}

	public void setWithdrawFlg(Integer withdrawFlg) {
		this.withdrawFlg = withdrawFlg;
	}

	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@PostLoad
	private void postLoad() {
		setServiceType(ServiceType.getById(serviceTypeId));
	}
	
	@PrePersist
	private void prePersist() {
		this.serviceTypeId = this.serviceType.getTypeId();
		this.inputDate = new Date();
		this.updateDate = new Date();
	}
	
	@PreUpdate
	private void preUpdate() {
		this.serviceTypeId = this.serviceType.getTypeId();
	}
}
